package com.njupt.towersystem.services.impl;

import com.njupt.towersystem.mapper.ManagerInfoMapper;
import com.njupt.towersystem.services.PowerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class PowerServiceImpl implements PowerService {
    @Resource
    private ManagerInfoMapper managerInfoMapper;

    @Override
    public void addNewRule(int rulerid, String rulername) {
        Map mp = new HashMap<>();
        mp.put("rulerid",rulerid);
        mp.put("rulername",rulername);
        managerInfoMapper.insertRule(mp);

    }

    @Override
    public void revokeUserRule(int rulerid, int userid) {
        Map mp = new HashMap<>();
        mp.put("rulerid",rulerid);
        mp.put("userid",userid);
        managerInfoMapper.delRule(mp);
    }

    @Override
    public void grantUserRule(int ruid, int rulerid, int userid) {
        Map mp = new HashMap<>();
        mp.put("ruid",ruid);
        mp.put("rulerid",rulerid);
        mp.put("userid",userid);
        managerInfoMapper.addRule(mp);
    }
}
